/*******************************************
Module: zt_list.h
E-Mail: 24zhutian@gmail.com
Notices: Copyright (c) 2007-2011 ls
*******************************************/
#ifndef zt_list_h
#define zt_list_h
#ifdef __cplusplus
extern "C" {
#endif
 
typedef struct zt_list_node_s{
	void *data;
	struct zt_list_node_s *prev;
	struct zt_list_node_s *next;
}zt_list_node_t;
 
typedef struct zt_list_s{
	size_t siz;
	zt_list_node_t *head;
	zt_list_node_t *tail;
}zt_list_t;
 
#define ZT_INIT_LIST(list) do{\
 	(list)->head=(list)->tail=NULL;(list)->siz=0;\
}while(0)
 
#define zt_list_for_each(list,pos) for(pos=(list)->head;\
	(pos)!=NULL;\
	pos=(pos)->next)

#define zt_list_head(list)	(list)->head
 
ZT_API void zt_list_add_head(zt_list_t *list,zt_list_node_t *node);
ZT_API void zt_list_add_tail(zt_list_t *list,zt_list_node_t *node);
ZT_API void zt_list_add_before(zt_list_t *list,zt_list_node_t *old,zt_list_node_t *node);
ZT_API void zt_list_add_after(zt_list_t *list,zt_list_node_t *old,zt_list_node_t *node);
ZT_API void zt_list_del(zt_list_t *list,zt_list_node_t *node);
ZT_API zt_list_node_t* zt_list_find(zt_list_t *list,void *key,int (*ZT_LIST_CMP)(void *,void *));

ZT_API int zt_list_int_cmp(void *n,void *k);
ZT_API int zt_list_uint_cmp(void *n,void *k);
ZT_API zt_int64_t zt_list_int64_cmp(void *n,void *k);
ZT_API zt_int64_t zt_list_uint64_cmp(void *n,void *k);
ZT_API int zt_list_str_cmp(void *n,void *k);
 
#ifdef __cplusplus
}
#endif /* C++ */
#endif /* zt_list_h */